/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				BinarySerialization
 
Function						: 				A simple Serialization class
****************************************************************************/

package serialization;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class BinarySerialization {
	public static boolean dump(Object obj, String filename){
		FileOutputStream fos = null;
		ObjectOutputStream out = null;
		try{
			fos = new FileOutputStream(filename);
			out = new ObjectOutputStream(fos);
			out.writeObject(obj);
			out.flush();
			out.close();
			return true;
		}catch(IOException ex){
			System.err.println("Exception! " + ex.getMessage());
			ex.printStackTrace();
			return false;
		}
	}
	
	public static Object load(String filename){
		FileInputStream fis = null;
		ObjectInputStream in = null;
		try {
			fis = new FileInputStream(filename);
			in = new ObjectInputStream(fis);
			Object obj = in.readObject();
			in.close();
			return obj;
		}catch(IOException ex){
			System.err.println("Exception! " + ex.getMessage());
			ex.printStackTrace();
			return null;
		}catch(ClassNotFoundException ex){
			System.err.println("Exception! " + ex.getMessage());
			ex.printStackTrace();
			return null;
		}
	}
}
